<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../../../css/api.css" />
    <link rel="stylesheet" href="../../../css/aui.css" />
</head>

<body>
    <ul class="aui-list aui-media-list" id="dbcontentlist">
    </ul>
</body>
<script type="text/javascript" src="../../../script/api.js"></script>
<script src="../../../script/doT.min.js" charset="utf-8"></script>
<script type="text/template" id="listemplate">
    {{~it:value:index}}
    <li class="aui-list-item aui-list-item-arrow" onclick="checodetail('{{=value.id}}')">
        <div class="aui-media-list-item-inner">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-text">
                    <div class="aui-list-item-title">{{=value.project_name}}</div>
                    <div class="aui-list-item-right">{{=value.update_time}}</div>
                </div>
                <div class="aui-list-item-text aui-ellipsis-2">
                  材料名称：{{=value.remark}};材料供应商：{{=value.material_server}}
                </div>
            </div>
        </div>
    </li>
    {{~}}
</script>
<script type="text/javascript">
    apiready = function() {
        // console.log(JSON.stringify(api.windows()));
        initdata();
        initRefresh();
    };
    // 初始化数据
    function initdata() {
        api.ajax({
            url: $api.SERVE_URL + 'index.php/index/Material/index',
            method: 'post',
            headers: {
                "token": $api.getStorage('token')
            },
            data: {
                values: {
                    'limit': 20,
                    'material_name': "",
                    'pid': "",
                    'state': "",
                    'token_uid': $api.getStorage('uid')
                }
            }
        }, function(ret, err) {
            if (ret) {
                if (ret.code === 200) {
                    api.refreshHeaderLoadDone();
                    var dataJson = ret.data.list
                    var tmpltxt = doT.template(document.getElementById("listemplate").innerHTML); //生成模板方法
                    document.getElementById("dbcontentlist").innerHTML = tmpltxt(dataJson); //数据渲染
                } else {
                    api.toast({
                        msg: ret.msg,
                        duration: 2000,
                        location: 'top'
                    });
                }
            } else {
                api.toast({
                    msg: err.msg,
                    duration: 2000,
                    location: 'top'
                });
            }
        });
    }
    // 查看详情
    function checodetail(id){
        api.openWin({
            name: 'db',
            url: '../detail/index.html',
            pageParam: {
              id: id
            }
        });

    }

    function initRefresh() {
      api.setRefreshHeaderInfo({
          visible: true,
          loadingImg: 'widget://image/refresh.png',
          bgColor: '#ccc',
          textColor: '#fff',
          textDown: '下拉刷新...',
          textUp: '松开刷新...',
          showTime: true
      }, function(ret, err) {
          initdata();
      });
    }
</script>

</html>
